package com.walle.sonar.export.report.reportdoc.module.issues;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.walle.ak47.commons.utils.FileUtils;
import com.walle.ak47.commons.utils.json.GBuilder;
import com.walle.sonar.export.report.api.issues.GetIssueInfos;
import com.walle.sonar.export.report.api.issues.IssueInfo;

public class Issueser {

	public static Map<String,IssueItemInfo> getIssues() {
		
		List<IssueInfo> issueInfos = GetIssueInfos.getAllIssues();
		
		Map<String,IssueItemInfo> issueItemInfos = new HashMap<String, IssueItemInfo>() ;
		if ( issueInfos!=null && !issueInfos.isEmpty() )
		{
			issueInfos.forEach(issueInfo->{
				issueItemInfos.put( issueInfo.getKey(), new IssueItemInfo(issueInfo.getComponent(), issueInfo.getSeverity(), 
																issueInfo.getLine(), issueInfo.getLineCode(), 
																issueInfo.getRule(), issueInfo.getShortDesc()) ) ;
			});
		}
		
		return issueItemInfos; 
	}
	
	public static void main(String[] args) {
		
		Map<String, IssueItemInfo> issues = Issueser.getIssues();
		String issuesJson = GBuilder.toJson(issues);
		FileUtils.writeFileText("E:/2.txt", issuesJson) ;
		
		
	}

}
